package com.orange.score.model.match;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class FollowMatchDBAdapter
{
  private static final String COLUMN_AWAY_CANTONESE_NAME = "away_cantonese_name";
  public static final String COLUMN_AWAY_TEAM_FIRSTHALF_SCORE = "away_team_firsthalf_score";
  private static final String COLUMN_AWAY_TEAM_IMAGE_URL = "away_image";
  public static final String COLUMN_AWAY_TEAM_NAME = "away_team_name";
  private static final String COLUMN_AWAY_TEAM_RANK = "away_rank";
  public static final String COLUMN_AWAY_TEAM_RED = "away_team_red";
  public static final String COLUMN_AWAY_TEAM_SCORE = "away_team_score";
  public static final String COLUMN_AWAY_TEAM_YELLOW = "away_team_yellow";
  public static final String COLUMN_CROWN_CHUPAN = "crown_chupan";
  public static final String COLUMN_DATE = "date";
  private static final String COLUMN_HAS_LINEUP = "has_lineup";
  private static final String COLUMN_HOME_CANTONESE_NAME = "home_cantonese_name";
  public static final String COLUMN_HOME_TEAM_FIRSTHALF_SCORE = "home_team_firsthalf_score";
  private static final String COLUMN_HOME_TEAM_IMAGE_URL = "home_image";
  public static final String COLUMN_HOME_TEAM_NAME = "home_team_name";
  private static final String COLUMN_HOME_TEAM_RANK = "home_rank";
  public static final String COLUMN_HOME_TEAM_RED = "home_team_red";
  public static final String COLUMN_HOME_TEAM_SCORE = "home_team_score";
  public static final String COLUMN_HOME_TEAM_YELLOW = "home_team_yellow";
  public static final String COLUMN_IS_FOLLOW = "is_follow";
  public static final String COLUMN_LEAGUE_ID = "league_id";
  public static final String COLUMN_LEAGUE_NAME = "league_name";
  public static final String COLUMN_MATCH_ID = "match_id";
  public static final String COLUMN_START_DATE = "start_date";
  public static final String COLUMN_STATUS = "status";
  private static final String DB_NAME = "ScoreDB.db";
  private static final int DB_VERSION = 1;
  public static final String SQL_CREATE_DB = "create table T_FOLLOW_MATCH (match_id TEXT primary key, league_id TEXT not null, status INTEGER not null, date TEXT not null, start_date TEXT, home_team_name TEXT not null, away_team_name TEXT not null, home_team_score TEXT, away_team_score TEXT, home_team_firsthalf_score TEXT, away_team_firsthalf_score TEXT, home_team_red TEXT, away_team_red TEXT, home_team_yellow TEXT, away_team_yellow TEXT, crown_chupan TEXT, league_name TEXT, is_follow INTEGER not null, home_cantonese_name TEXT, away_cantonese_name TEXT, home_rank TEXT, away_rank TEXT, home_image TEXT, away_image TEXT, has_lineup TEXT);";
  private static final String TABLE_FOLLOW_MATCH = "T_FOLLOW_MATCH";
  private static final String TAG = "DBAdapter";
  private final Context context;
  private SQLiteDatabase db;
  private MyDbHelper dbHelper;

  public FollowMatchDBAdapter(Context paramContext)
  {
    this.context = paramContext;
    this.dbHelper = new MyDbHelper(this.context, "ScoreDB.db", null, 1);
  }

  private ContentValues fromMatch(Match paramMatch)
  {
    ContentValues localContentValues = new ContentValues();
    localContentValues.put("match_id", paramMatch.matchId);
    localContentValues.put("league_id", paramMatch.leagueId);
    localContentValues.put("status", Integer.valueOf(paramMatch.status));
    localContentValues.put("date", paramMatch.date);
    localContentValues.put("start_date", paramMatch.startDate);
    localContentValues.put("home_team_name", paramMatch.homeTeamName);
    localContentValues.put("away_team_name", paramMatch.awayTeamName);
    localContentValues.put("home_team_score", paramMatch.homeTeamScore);
    localContentValues.put("away_team_score", paramMatch.awayTeamScore);
    localContentValues.put("home_team_firsthalf_score", paramMatch.homeTeamFirstHalfScore);
    localContentValues.put("away_team_firsthalf_score", paramMatch.awayTeamFirstHalfScore);
    localContentValues.put("home_team_red", paramMatch.homeTeamRed);
    localContentValues.put("away_team_red", paramMatch.awayTeamRed);
    localContentValues.put("home_team_yellow", paramMatch.homeTeamYellow);
    localContentValues.put("away_team_yellow", paramMatch.awayTeamYellow);
    localContentValues.put("crown_chupan", paramMatch.crownChupan);
    localContentValues.put("league_name", paramMatch.getLeagueName());
    localContentValues.put("is_follow", Integer.valueOf(1));
    localContentValues.put("home_cantonese_name", paramMatch.homeCantoneseName);
    localContentValues.put("away_cantonese_name", paramMatch.awayCantoneseName);
    localContentValues.put("home_rank", paramMatch.homeTeamRank);
    localContentValues.put("away_rank", paramMatch.awayTeamRank);
    localContentValues.put("home_image", paramMatch.homeTeamImageUrl);
    localContentValues.put("away_image", paramMatch.awayTeamImageUrl);
    localContentValues.put("has_lineup", paramMatch.hasLineup);
    return localContentValues;
  }

  /**
   * @deprecated
   */
  public void close()
  {
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<close db> but db is null or not open");
        monitorexit;
        return;
      }
      this.db.close();
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public Cursor findEntryByMatch(Match paramMatch)
  {
    Object localObject2;
    Cursor localCursor;
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<findEntryByMatch> but db is null or not open");
        localObject2 = null;
        monitorexit;
        return localObject2;
      }
      String str = "match_id='" + paramMatch.getMatchId() + "'";
      localCursor = this.db.query("T_FOLLOW_MATCH", null, str, null, null, null, null);
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public Cursor getAllEntries()
  {
    Object localObject2;
    Cursor localCursor;
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<findEntryByMatch> but db is null or not open");
        localObject2 = null;
        monitorexit;
        return localObject2;
      }
      localCursor = this.db.query("T_FOLLOW_MATCH", null, null, null, null, null, null);
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public long insertEntry(Match paramMatch)
  {
    long l1;
    long l2;
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<insertEntry> but db is null or not open");
        l1 = -1L;
        monitorexit;
        return l1;
      }
      l2 = this.db.insert("T_FOLLOW_MATCH", null, fromMatch(paramMatch));
      Log.d("DBAdapter", "insert entry result = " + l2);
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public FollowMatchDBAdapter open()
    throws SQLException
  {
    FollowMatchDBAdapter localFollowMatchDBAdapter;
    monitorenter;
    try
    {
      if (this.db != null)
      {
        boolean bool = this.db.isOpen();
        if (bool)
        {
          localFollowMatchDBAdapter = this;
          monitorexit;
          return localFollowMatchDBAdapter;
        }
      }
      this.db = this.dbHelper.getWritableDatabase();
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public long removeEntry(String paramString)
  {
    long l1;
    long l2;
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<removeEntry> but db is null or not open");
        l1 = -1L;
        monitorexit;
        return l1;
      }
      l2 = this.db.delete("T_FOLLOW_MATCH", "match_id='" + paramString + "'", null);
      Log.d("DBAdapter", "delete entry, matchId=" + paramString + ", result = " + l2);
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public int updateEntry(Match paramMatch)
  {
    int i;
    int j;
    monitorenter;
    try
    {
      if ((this.db == null) || (!(this.db.isOpen())))
      {
        Log.d("DBAdapter", "<updateEntry> but db is null or not open");
        i = -1;
        monitorexit;
        return i;
      }
      Log.d("DBAdapter", "update entry, match = " + paramMatch.toString());
      String str = "match_id='" + paramMatch.getMatchId() + "'";
      j = this.db.update("T_FOLLOW_MATCH", fromMatch(paramMatch), str, null);
    }
    finally
    {
      monitorexit;
    }
  }

  private static class MyDbHelper extends SQLiteOpenHelper
  {
    public MyDbHelper(Context paramContext, String paramString, SQLiteDatabase.CursorFactory paramCursorFactory, int paramInt)
    {
      super(paramContext, paramString, paramCursorFactory, paramInt);
    }

    public void onCreate(SQLiteDatabase paramSQLiteDatabase)
    {
      paramSQLiteDatabase.execSQL("create table T_FOLLOW_MATCH (match_id TEXT primary key, league_id TEXT not null, status INTEGER not null, date TEXT not null, start_date TEXT, home_team_name TEXT not null, away_team_name TEXT not null, home_team_score TEXT, away_team_score TEXT, home_team_firsthalf_score TEXT, away_team_firsthalf_score TEXT, home_team_red TEXT, away_team_red TEXT, home_team_yellow TEXT, away_team_yellow TEXT, crown_chupan TEXT, league_name TEXT, is_follow INTEGER not null, home_cantonese_name TEXT, away_cantonese_name TEXT, home_rank TEXT, away_rank TEXT, home_image TEXT, away_image TEXT, has_lineup TEXT);");
    }

    public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
    {
    }
  }
}